#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_ mysql_connector.py
# author:Jackiex
# datetime:2023/5/11 15:01
# software: PyCharm

"""
 mysql-connector 是MySQL官方提供的数据库访问驱动
 安装：pip install mysql-connector
"""

import mysql.connector

mydb = mysql.connector.connect(
    host="127.0.0.1",
    user="test",
    password="123456",
    database="testdb"
)

# print(mydb)


# 1 往数据库中添加记录
# cursor = mydb.cursor()
# cursor.execute("INSERT INTO `student` VALUES ('9541105', '王小五', '女', '21', '01', '95312', '北京市昌平区华北电力大学')")
# mydb.commit()
#
# cursor.close()
# mydb.close()

# 2 查询数据库中的记录
# cursor = mydb.cursor()
#
# cursor.execute("select * from  student where Sage>20")
#
# res = cursor.fetchall()
#
# print(res)
#
# cursor.close()
# mydb.close()


